import 'package:shared_preferences/shared_preferences.dart';

import 'config.dart';



class SharedPreferencesUtil {

  SharedPreferencesUtil._();

  static SharedPreferencesUtil _preferencesUtil;

  static SharedPreferencesUtil getInstance(){
    if(_preferencesUtil == null){
      _preferencesUtil = SharedPreferencesUtil._();
    }
    return _preferencesUtil;
  }


  static Future getData<T>(String key) async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    var data = preferences.get(key);
    return data;
  }

  static putData(String key, var value) async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    value is String
        ? preferences.setString(key, value)
        : value is int
            ? preferences.setInt(key, value)
            : value is double
                ? preferences.setDouble(key, value)
                : value is bool
                    ? preferences.setBool(key, value)
                    : value is List<String>
                        ? preferences.setStringList(key, value)
                        : throw Exception('Type Error,this value must be Basic data type!');
  }

}
